from rest_framework import serializers
from rest_framework.authtoken.models import Token
from django.contrib.auth.models import User
from rest_framework import response
from account  import models as  models_account
from course import  models as models_course
from datetime import datetime
from django.db.models import Q
from utils import choices
import rest_framework as drf


class CourseUpdateSerializer(serializers.Serializer):
    course_id = serializers.IntegerField(write_only=True)
    status = serializers.CharField(write_only=True)


class CourseBaseSerializer(serializers.Serializer):
    course_name=serializers.CharField()
    programming_language=serializers.CharField()
    account_id=serializers.IntegerField(read_only=True)
    start_time=serializers.DateField()
    end_time=serializers.DateField()
    course_image=serializers.ImageField()



class CourseApplySerializer(serializers.Serializer):
    course_id=serializers.IntegerField(write_only=True)
    account_id=serializers.IntegerField(write_only=True)
    status=serializers.CharField(write_only=True)
    def get_serialized_data(self):
        pass



class CourseCreateAssignmentSerializer(serializers.Serializer):
    course_id=serializers.IntegerField( write_only=True )
    dead_line=serializers.DateTimeField(write_only=True)
    title=serializers.CharField(write_only=True)

    type=serializers.IntegerField(write_only=True)
    ti=serializers.CharField(write_only=True)

    '''class Meta:
        model = course_models.MyAssignment
        fields = (
             'dead_line',
            'title', 'type',
            'text',
        )

    def get_text(self, obj):
        request = self.context['request']
        return request.data.get('text')

    def create(self, validated_data):
        assignment = course_models.Assignments.objects.create(
            create_time=datetime.now(),
            title=validated_data['title'],
            type='0',
        )
        # -----------------create a classroom asignment--------------
        ti = course_models.Ti.objects.create(
            course_id=validated_data['course_id'],
            assignment_id=assignment.id,
            text=validated_data['text']
        )

        assignment.text=ti.text
        return assignment'''


class CourseAssignmentsSerializer(serializers.ModelSerializer):
    class Meat:
        model=models_course.MyAssignment
        fields = "__all__"


class CourseMyAllCourseSerializer(serializers.ModelSerializer):
    class Meta:
        model=models_course.Course
        fields="__all__"


class CourseAllAssignmentSerializer(serializers.Serializer):
    programming_language=serializers.CharField(max_length=40)
    create_time = serializers.DateTimeField()
    dead_line = serializers.DateField()
    title = serializers.CharField(max_length=80)
    type = serializers.CharField(max_length=20)
    assignment_id=serializers.IntegerField()
    course_name=serializers.CharField(max_length=80)
    course_id=serializers.IntegerField()

    class Struct(object):
        def __init__(self,programming_language,create_time,dead_line,title,type,assignment_id,course_name,course_id):
            self.programming_language=programming_language
            self.create_time=create_time
            self.dead_line=dead_line
            self.title=title
            self.type=type
            self.assignment_id=assignment_id
            self.course_name=course_name
            self.course_id=course_id

class CourseAssignmentTextSerializer(serializers.Serializer):
    ti_id=serializers.IntegerField()
    project_id=serializers.IntegerField()
    text=serializers.CharField(
        max_length=1000,
    )

    class Struct(object):
        def __init__(self, ti_id, text, project_id):
            self.ti_id = ti_id
            self.text = text
            self.project_id=project_id


class CourseAllStudentSerializer(serializers.Serializer):
    real_name=serializers.CharField(max_length=20,)
    class_name=serializers.CharField(max_length=40,)
    account_id=serializers.IntegerField()
    class_id=serializers.IntegerField()
    student_number=serializers.CharField(max_length=40)

    class Struct(object):
        def __init__(self, real_name, class_name,account_id,class_id,student_number):
            self.real_name = real_name
            self.class_name = class_name
            self.account_id=account_id
            self.class_id=class_id
            self.student_number=student_number


class CourseAssignmentDetailSerializer(serializers.Serializer):
    real_name = serializers.CharField(max_length=20)
    student_number = serializers.CharField(max_length=40)
    submited = serializers.NullBooleanField()
    compile_successed = serializers.NullBooleanField()
    project_id = serializers.IntegerField()
    class_name=serializers.CharField(max_length=40)

    class Struct(object):
        def __init__(self, real_name, student_number, submited, compile_successed, project_id,class_name):
            self.real_name = real_name
            self.student_number = student_number
            self.submited = submited
            self.compile_successed = compile_successed
            self.project_id = project_id
            self.class_name=class_name